package com.chenhs.oop.study.IO流;

import org.junit.Test;

import java.io.*;

/**
 * @className: com.chenhs.oop.study.IO流-> IO5文件拷贝_字符流
 * @description: 这个类是做做什么得吖，小朋友？
 * @author: chenhs
 * @createDate: 2022-12-26 22:27
 * @version: 1.0
 */
public class IO6文件拷贝_字符流 {
//    读一句写一句,写入文件父路径如果不存在会直接报错。
    @Test
    public void t() throws IOException {
        String wPath="D:\\temp\\字符流copy.txt";
        File file = new File(wPath);
        File fileParentFile = file.getParentFile();
        if(!fileParentFile.exists()){
            fileParentFile.mkdirs();
        }
        String line;
        BufferedReader reader = new BufferedReader(new FileReader("D:\\temp\\字符流2.txt"));
        BufferedWriter writer = new BufferedWriter(new FileWriter(wPath));
        while ((line=reader.readLine())!=null){
            writer.write(line);
            writer.newLine();
        }
        reader.close();
        writer.close();
        System.out.println("拷贝完成");
    }
}
